mirror of
https://github.com/fergalmoran/picard.git
synced 2026-02-24 00:26:08 +00:00
Merge pull request #829 from vishichoudhary/PICARD-1184
PICARD-1184: Fix multi click weird issues
This commit is contained in:
@@ -69,6 +69,9 @@ PICARD_URLS = {
|
||||
'acoustid_track': "https://acoustid.org/track/",
|
||||
}
|
||||
|
||||
# Various option for plugin action
|
||||
PLUGIN_ACTION_NONE, PLUGIN_ACTION_UPDATE, PLUGIN_ACTION_INSTALL = range(3)
|
||||
|
||||
# Various Artists MBID
|
||||
VARIOUS_ARTISTS_ID = '89ad4ac3-39f7-470e-963a-56509c546377'
|
||||
|
||||
|
||||
@@ -36,10 +36,9 @@ from picard import (config,
|
||||
version_from_string,
|
||||
version_to_string,
|
||||
VersionError)
|
||||
from picard.const import USER_PLUGIN_DIR, PLUGINS_API
|
||||
from picard.const import USER_PLUGIN_DIR, PLUGINS_API, PLUGIN_ACTION_UPDATE
|
||||
from picard.util import load_json
|
||||
|
||||
|
||||
_suffixes = [s[0] for s in imp.get_suffixes()]
|
||||
_package_entries = ["__init__.py", "__init__.pyc", "__init__.pyo"]
|
||||
_extension_points = []
|
||||
@@ -376,7 +375,7 @@ class PluginManager(QtCore.QObject):
|
||||
log.debug("Removing file %r", filepath)
|
||||
os.remove(filepath)
|
||||
|
||||
def install_plugin(self, path, overwrite_confirm=None, plugin_name=None,
|
||||
def install_plugin(self, path, action, overwrite_confirm=None, plugin_name=None,
|
||||
plugin_data=None):
|
||||
"""
|
||||
path is either:
|
||||
@@ -394,13 +393,11 @@ class PluginManager(QtCore.QObject):
|
||||
plugin_name = os.path.splitext(zip_plugin)[0]
|
||||
if plugin_name:
|
||||
try:
|
||||
dirpath, filepaths = self._get_existing_paths(plugin_name)
|
||||
update = dirpath or filepaths
|
||||
if plugin_data and plugin_name:
|
||||
# zipped module from download
|
||||
zip_plugin = plugin_name + '.zip'
|
||||
dst = os.path.join(USER_PLUGIN_DIR, zip_plugin)
|
||||
if update:
|
||||
if action == PLUGIN_ACTION_UPDATE:
|
||||
dst += '.update'
|
||||
if os.path.isfile(dst):
|
||||
os.remove(dst)
|
||||
@@ -421,19 +418,19 @@ class PluginManager(QtCore.QObject):
|
||||
raise
|
||||
elif os.path.isfile(path):
|
||||
dst = os.path.join(USER_PLUGIN_DIR, os.path.basename(path))
|
||||
if update:
|
||||
if action == PLUGIN_ACTION_UPDATE:
|
||||
dst += '.update'
|
||||
if os.path.isfile(dst):
|
||||
os.remove(dst)
|
||||
shutil.copy2(path, dst)
|
||||
elif os.path.isdir(path):
|
||||
dst = os.path.join(USER_PLUGIN_DIR, plugin_name)
|
||||
if update:
|
||||
if action == PLUGIN_ACTION_UPDATE:
|
||||
dst += '.update'
|
||||
if os.path.isdir(dst):
|
||||
shutil.rmtree(dst)
|
||||
shutil.copytree(path, dst)
|
||||
if not update:
|
||||
if action != PLUGIN_ACTION_UPDATE:
|
||||
installed_plugin = self.load_plugin(zip_plugin or plugin_name, USER_PLUGIN_DIR)
|
||||
if installed_plugin is not None:
|
||||
self.plugin_installed.emit(installed_plugin, False)
|
||||
|
||||
@@ -29,12 +29,14 @@ from picard import config, log
|
||||
from picard.const import (
|
||||
USER_PLUGIN_DIR,
|
||||
PLUGINS_API,
|
||||
PLUGIN_ACTION_NONE,
|
||||
PLUGIN_ACTION_INSTALL,
|
||||
PLUGIN_ACTION_UPDATE,
|
||||
)
|
||||
from picard.ui import HashableTreeWidgetItem
|
||||
from picard.ui.options import OptionsPage, register_options_page
|
||||
from picard.ui.ui_options_plugins import Ui_PluginsOptionsPage
|
||||
|
||||
|
||||
class PluginTreeWidgetItem(HashableTreeWidgetItem):
|
||||
|
||||
def __lt__(self, other):
|
||||
@@ -245,24 +247,31 @@ class PluginsOptionsPage(OptionsPage):
|
||||
else:
|
||||
item.setText(1, plugin.version)
|
||||
|
||||
label = None
|
||||
bt_action = PLUGIN_ACTION_NONE
|
||||
if plugin.can_be_updated:
|
||||
label = _("Update")
|
||||
bt_action = PLUGIN_ACTION_UPDATE
|
||||
elif plugin.can_be_downloaded:
|
||||
label = _("Install")
|
||||
bt_action = PLUGIN_ACTION_INSTALL
|
||||
item.setFlags(item.flags() ^ QtCore.Qt.ItemIsUserCheckable)
|
||||
|
||||
if label is not None:
|
||||
if bt_action != PLUGIN_ACTION_NONE:
|
||||
labels = {
|
||||
PLUGIN_ACTION_UPDATE: N_("Update"),
|
||||
PLUGIN_ACTION_INSTALL: N_("Install"),
|
||||
}
|
||||
label = _(labels[bt_action])
|
||||
button = QtWidgets.QPushButton(label)
|
||||
button.setMaximumHeight(button.fontMetrics().boundingRect(label).height() + 7)
|
||||
self.ui.plugins.setItemWidget(item, 2, button)
|
||||
|
||||
def download_button_process():
|
||||
def download_button_process(action):
|
||||
self.ui.plugins.setCurrentItem(item)
|
||||
self.download_plugin()
|
||||
button.released.connect(download_button_process)
|
||||
self.download_plugin(action)
|
||||
|
||||
button.released.connect(partial(download_button_process, bt_action))
|
||||
else:
|
||||
# Note: setText() don't work after it was set to a button
|
||||
label = None
|
||||
if plugin.marked_for_update:
|
||||
label = _("Updated")
|
||||
else:
|
||||
@@ -315,7 +324,7 @@ class PluginsOptionsPage(OptionsPage):
|
||||
for path in files:
|
||||
self.tagger.pluginmanager.install_plugin(path)
|
||||
|
||||
def download_plugin(self):
|
||||
def download_plugin(self, action):
|
||||
selected = self.ui.plugins.selectedItems()[0]
|
||||
plugin = self.items[selected]
|
||||
|
||||
@@ -323,14 +332,14 @@ class PluginsOptionsPage(OptionsPage):
|
||||
PLUGINS_API['host'],
|
||||
PLUGINS_API['port'],
|
||||
PLUGINS_API['endpoint']['download'],
|
||||
partial(self.download_handler, plugin=plugin),
|
||||
partial(self.download_handler, action, plugin=plugin),
|
||||
parse_response_type=None,
|
||||
priority=True,
|
||||
important=True,
|
||||
queryargs={"id": plugin.module_name}
|
||||
)
|
||||
|
||||
def download_handler(self, response, reply, error, plugin):
|
||||
def download_handler(self, action, response, reply, error, plugin):
|
||||
if error:
|
||||
msgbox = QtWidgets.QMessageBox(self)
|
||||
msgbox.setText(_("The plugin '%s' could not be downloaded.") % plugin.module_name)
|
||||
@@ -343,8 +352,9 @@ class PluginsOptionsPage(OptionsPage):
|
||||
|
||||
self.tagger.pluginmanager.install_plugin(
|
||||
None,
|
||||
action,
|
||||
plugin_name=plugin.module_name,
|
||||
plugin_data=response
|
||||
plugin_data=response,
|
||||
)
|
||||
|
||||
def open_plugin_dir(self):
|
||||
|
||||
Reference in New Issue
Block a user