Skip to content

Commit

Permalink
[Plugin manager] Replace confirmation popup dialogs with an internal …
Browse files Browse the repository at this point in the history
…QgsMessageBar
  • Loading branch information
borysiasty committed Mar 27, 2014
1 parent 7a70041 commit cdbe1ee
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 44 deletions.
4 changes: 4 additions & 0 deletions python/gui/qgspluginmanagerinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ class QgsPluginManagerInterface : QObject

//! show the Plugin Manager window and optionally open tab tabIndex
virtual void showPluginManager( int tabIndex = -1 ) = 0;

//! show the given message in the Plugin Manager internal message bar
virtual void pushMessage( const QString &text, QgsMessageBar::MessageLevel level = QgsMessageBar::INFO, int duration = -1 ) = 0;

};
29 changes: 20 additions & 9 deletions python/pyplugin_installer/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import QgsMessageBar
from qgis.utils import iface, startPlugin, unloadPlugin, loadPlugin, reloadPlugin, updateAvailablePlugins
from installer_data import *
from qgsplugininstallerinstallingdialog import QgsPluginInstallerInstallingDialog
Expand Down Expand Up @@ -273,6 +274,7 @@ def upgradeAllUpgradeable(self):
# ----------------------------------------- #
def installPlugin(self, key, quiet=False):
""" Install given plugin """
error = False
infoString = ('','')
plugin = plugins.all()[key]
previousStatus = plugin["status"]
Expand All @@ -286,8 +288,10 @@ def installPlugin(self, key, quiet=False):
dlg.exec_()

if dlg.result():
error = True
infoString = (self.tr("Plugin installation failed"), dlg.result())
elif not QDir( qgis.utils.home_plugin_path + "/" + key ).exists():
error = True
infoString = (self.tr("Plugin has disappeared"), self.tr("The plugin seems to have been installed but I don't know where. Probably the plugin package contained a wrong named directory.\nPlease search the list of installed plugins. I'm nearly sure you'll find the plugin there, but I just can't determine which of them it is. It also means that I won't be able to determine if this plugin is installed and inform you about available updates. However the plugin may work. Please contact the plugin author and submit this issue."))
QApplication.setOverrideCursor(Qt.WaitCursor)
plugins.getAllInstalled()
Expand All @@ -305,15 +309,15 @@ def installPlugin(self, key, quiet=False):
plugin = plugins.all()[key]
if not plugin["error"]:
if previousStatus in ["not installed", "new"]:
infoString = (self.tr("Plugin installed successfully"), self.tr("Plugin installed successfully"))
infoString = (self.tr("Plugin installed successfully"), "")
if startPlugin(plugin["id"]):
settings = QSettings()
settings.setValue("/PythonPlugins/"+plugin["id"], True)
else:
settings = QSettings()
if settings.value("/PythonPlugins/"+key, False, type=bool): # plugin will be reloaded on the fly only if currently loaded
reloadPlugin(key) # unloadPlugin + loadPlugin + startPlugin
infoString = (self.tr("Plugin reinstalled successfully"), self.tr("Plugin reinstalled successfully"))
infoString = (self.tr("Plugin reinstalled successfully"), "")
else:
unloadPlugin(key) # Just for a case. Will exit quietly if really not loaded
loadPlugin(key)
Expand All @@ -339,6 +343,7 @@ def installPlugin(self, key, quiet=False):
pluginDir = qgis.utils.home_plugin_path + "/" + plugin["id"]
removeDir(pluginDir)
if QDir(pluginDir).exists():
error = True
infoString = (self.tr("Plugin uninstall failed"), result)
try:
exec ("sys.path_importer_cache.clear()")
Expand All @@ -357,7 +362,9 @@ def installPlugin(self, key, quiet=False):
self.exportPluginsToManager()

if infoString[0]:
QMessageBox.information(iface.mainWindow(), infoString[0], infoString[1])
level = error and QgsMessageBar.CRITICAL or QgsMessageBar.INFO
msg = "<b>%s:</b>%s" % (infoString[0], infoString[1])
iface.pluginManagerInterface().pushMessage(msg, level)


# ----------------------------------------- #
Expand All @@ -376,14 +383,17 @@ def uninstallPlugin(self, key, quiet=False):
if QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), warning , QMessageBox.Yes, QMessageBox.No) == QMessageBox.No:
return
# unload the plugin
QApplication.setOverrideCursor(Qt.WaitCursor)
try:
unloadPlugin(key)
except:
pass
pluginDir = qgis.utils.home_plugin_path + "/" + plugin["id"]
result = removeDir(pluginDir)
if result:
QMessageBox.warning(iface.mainWindow(), self.tr("Plugin uninstall failed"), result)
QApplication.restoreOverrideCursor()
msg = "<b>%s:</b>%s" % (self.tr("Plugin uninstall failed"), result)
iface.pluginManagerInterface().pushMessage(msg, QgsMessageBar.CRITICAL)
else:
# safe remove
try:
Expand All @@ -402,7 +412,8 @@ def uninstallPlugin(self, key, quiet=False):
plugins.getAllInstalled()
plugins.rebuild()
self.exportPluginsToManager()
QMessageBox.information(iface.mainWindow(), self.tr("Plugin uninstalled successfully"), self.tr("Plugin uninstalled successfully"))
QApplication.restoreOverrideCursor()
iface.pluginManagerInterface().pushMessage(self.tr("Plugin uninstalled successfully"), QgsMessageBar.INFO)


# ----------------------------------------- #
Expand All @@ -415,7 +426,7 @@ def addRepository(self):
return
for i in repositories.all().values():
if dlg.editURL.text().strip() == i["url"]:
QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), self.tr("Unable to add another repository with the same URL!"))
iface.pluginManagerInterface().pushMessage(self.tr("Unable to add another repository with the same URL!"), QgsMessageBar.WARNING)
return
settings = QSettings()
settings.beginGroup(reposGroup)
Expand All @@ -424,7 +435,7 @@ def addRepository(self):
if repositories.all().has_key(reposName):
reposName = reposName + "(2)"
# add to settings
settings.setValue(reposName+"/url", reposURL )
settings.setValue(reposName+"/url", reposURL)
settings.setValue(reposName+"/enabled", bool(dlg.checkBoxEnabled.checkState()))
# refresh lists and populate widgets
plugins.removeRepository(reposName)
Expand Down Expand Up @@ -454,7 +465,7 @@ def editRepository(self, reposName):
return # nothing to do if cancelled
for i in repositories.all().values():
if dlg.editURL.text().strip() == i["url"] and dlg.editURL.text().strip() != repositories.all()[reposName]["url"]:
QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), self.tr("Unable to add another repository with the same URL!"))
iface.pluginManagerInterface().pushMessage(self.tr("Unable to add another repository with the same URL!"), QgsMessageBar.WARNING)
return
# delete old repo from QSettings and create new one
settings = QSettings()
Expand Down Expand Up @@ -482,7 +493,7 @@ def deleteRepository(self, reposName):
settings = QSettings()
settings.beginGroup(reposGroup)
if settings.value(reposName+"/url", "", type=unicode) == officialRepo[1]:
QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), self.tr("You can't remove the official QGIS Plugin Repository. You can disable it if needed."))
iface.pluginManagerInterface().pushMessage(self.tr("You can't remove the official QGIS Plugin Repository. You can disable it if needed."), QgsMessageBar.WARNING)
return
warning = self.tr("Are you sure you want to remove the following repository?") + "\n" + reposName
if QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), warning , QMessageBox.Yes, QMessageBox.No) == QMessageBox.No:
Expand Down
7 changes: 7 additions & 0 deletions src/app/pluginmanager/qgsapppluginmanagerinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,10 @@ void QgsAppPluginManagerInterface::addToRepositoryList( QMap<QString, QString> r
{
mPluginManager->addToRepositoryList( repository );
}


//! show the given message in the Plugin Manager internal message bar
void QgsAppPluginManagerInterface::pushMessage( const QString &text, QgsMessageBar::MessageLevel level, int duration )
{
mPluginManager->pushMessage( text, level, duration );
}
3 changes: 3 additions & 0 deletions src/app/pluginmanager/qgsapppluginmanagerinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class QgsAppPluginManagerInterface : public QgsPluginManagerInterface
//! show the Plugin Manager window and optionally open tab tabIndex
void showPluginManager( int tabIndex = -1 );

//! show the given message in the Plugin Manager internal message bar
void pushMessage( const QString &text, QgsMessageBar::MessageLevel level = QgsMessageBar::INFO, int duration = -1 );

private:

//! Pointer to QgsPluginManager object
Expand Down
38 changes: 32 additions & 6 deletions src/app/pluginmanager/qgspluginmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <QTimer>

#include "qgis.h"
#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsconfig.h"
#include "qgsproviderregistry.h"
Expand Down Expand Up @@ -111,6 +112,11 @@ QgsPluginManager::QgsPluginManager( QWidget * parent, bool pluginsAreEnabled, Qt
buttonInstall->hide();
buttonUninstall->hide();
frameSettings->setHidden( true );

// Init the message bar instance
msgBar = new QgsMessageBar( this );
msgBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
vlayoutRightColumn->insertWidget( 0, msgBar );
}


Expand Down Expand Up @@ -463,6 +469,13 @@ void QgsPluginManager::reloadModelData()
{
mModelPlugins->clear();

if ( !mCurrentlyDisplayedPlugin.isEmpty() )
{
tbDetails->setHtml( "" );
buttonInstall->setEnabled( false );
buttonUninstall->setEnabled( false );
}

for ( QMap<QString, QMap<QString, QString> >::iterator it = mPlugins.begin();
it != mPlugins.end();
++it )
Expand Down Expand Up @@ -1016,11 +1029,8 @@ void QgsPluginManager::currentPluginChanged( const QModelIndex & theIndex )
{
if ( theIndex.column() == 0 )
{
// If the model has been filtered, the index row in the proxy won't match the index row in the underlying model
// so we need to jump through this little hoop to get the correct item
QModelIndex realIndex = mModelProxy->mapToSource( theIndex );
QStandardItem* mypItem = mModelPlugins->itemFromIndex( realIndex );
showPluginDetails( mypItem );
// Do exactly the same as if a plugin was clicked
on_vwPlugins_clicked( theIndex );
}
}

Expand All @@ -1038,8 +1048,10 @@ void QgsPluginManager::on_vwPlugins_clicked( const QModelIndex &theIndex )
{
//The item is inactive (uncompatible or broken plugin), so it can't be selected. Display it's data anyway.
vwPlugins->clearSelection();
showPluginDetails( mypItem );
}
// Display details in any case: selection changed, inactive button clicked,
// or previously selected plugin clicked (while details view contains the welcome message for a category)
showPluginDetails( mypItem );
}
}

Expand Down Expand Up @@ -1363,6 +1375,8 @@ void QgsPluginManager::updateWindowTitle( )
}
}



void QgsPluginManager::showEvent( QShowEvent* e )
{
if ( mInit )
Expand All @@ -1377,3 +1391,15 @@ void QgsPluginManager::showEvent( QShowEvent* e )
QDialog::showEvent( e );
}



void QgsPluginManager::pushMessage( const QString &text, QgsMessageBar::MessageLevel level, int duration )
{
if ( duration == -1 )
{
duration = QgisApp::instance()->messageTimeout();
}
msgBar->pushMessage( text, level, duration );
}


6 changes: 6 additions & 0 deletions src/app/pluginmanager/qgspluginmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "qgscontexthelp.h"
#include "qgspythonutils.h"
#include "qgspluginsortfilterproxymodel.h"
#include "qgsmessagebar.h"

const int PLUGMAN_TAB_ALL = 0;
const int PLUGMAN_TAB_INSTALLED = 1;
Expand Down Expand Up @@ -163,6 +164,9 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
//! Enable all repositories disabled by "Enable selected repository only"
void clearRepositoryFilter( );

//! show the given message in the Plugin Manager internal message bar
void pushMessage( const QString &text, QgsMessageBar::MessageLevel level, int duration );

protected:
//! Reimplement QgsOptionsDialogBase method as we have a custom window title what would be overwritten by this method
void showEvent( QShowEvent* e );
Expand Down Expand Up @@ -208,6 +212,8 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
QString mCurrentlyDisplayedPlugin;

QList<int> mCheckingOnStartIntervals;

QgsMessageBar *msgBar;
};

#endif
3 changes: 3 additions & 0 deletions src/gui/qgspluginmanagerinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QObject>
#include <QString>
#include <QMap>
#include "qgsmessagebar.h"

class GUI_EXPORT QgsPluginManagerInterface : public QObject
{
Expand Down Expand Up @@ -54,6 +55,8 @@ class GUI_EXPORT QgsPluginManagerInterface : public QObject
//! show the Plugin Manager window and optionally open tab tabIndex
virtual void showPluginManager( int tabIndex = -1 ) = 0;

//! show the given message in the Plugin Manager internal message bar
virtual void pushMessage( const QString &text, QgsMessageBar::MessageLevel level = QgsMessageBar::INFO, int duration = -1 ) = 0;
};

#endif
59 changes: 30 additions & 29 deletions src/ui/qgspluginmanagerbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
<layout class="QVBoxLayout" name="vlayoutRightColumn">
<property name="spacing">
<number>6</number>
</property>
Expand Down Expand Up @@ -467,33 +467,31 @@
<property name="bottomMargin">
<number>0</number>
</property>

<item>
<widget class="QLabel" name="labelNoPython">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>The settings on this tab are only applicable for Python Plugins. No Python support detected, thus no settings available.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="margin">
<number>20</number>
</property>
<property name="indent">
<number>0</number>
</property>
</widget>
</item>

<item>
<widget class="QLabel" name="labelNoPython">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>The settings on this tab are only applicable for Python Plugins. No Python support detected, thus no settings available.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="margin">
<number>20</number>
</property>
<property name="indent">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frameSettings">
<property name="sizePolicy">
Expand All @@ -509,6 +507,9 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
Expand All @@ -519,7 +520,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>574</width>
<width>582</width>
<height>653</height>
</rect>
</property>
Expand Down

1 comment on commit cdbe1ee

@NathanW2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff

Please sign in to comment.