Skip to content
Permalink
Browse files
[Plugin manager] Replace confirmation popup dialogs with an internal …
…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.
@@ -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;

};
@@ -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
@@ -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"]
@@ -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()
@@ -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)
@@ -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()")
@@ -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)


# ----------------------------------------- #
@@ -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:
@@ -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)


# ----------------------------------------- #
@@ -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)
@@ -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)
@@ -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()
@@ -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:
@@ -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 );
}
@@ -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
@@ -32,6 +32,7 @@
#include <QTimer>

#include "qgis.h"
#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsconfig.h"
#include "qgsproviderregistry.h"
@@ -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 );
}


@@ -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 )
@@ -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 );
}
}

@@ -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 );
}
}

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



void QgsPluginManager::showEvent( QShowEvent* e )
{
if ( mInit )
@@ -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 );
}


@@ -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;
@@ -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 );
@@ -208,6 +212,8 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
QString mCurrentlyDisplayedPlugin;

QList<int> mCheckingOnStartIntervals;

QgsMessageBar *msgBar;
};

#endif
@@ -20,6 +20,7 @@
#include <QObject>
#include <QString>
#include <QMap>
#include "qgsmessagebar.h"

class GUI_EXPORT QgsPluginManagerInterface : public QObject
{
@@ -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
@@ -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>
@@ -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">
@@ -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">
@@ -519,7 +520,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>574</width>
<width>582</width>
<height>653</height>
</rect>
</property>

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.